package ar.com.nextel.corba.client;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Properties;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

import ar.com.nextel.corba.generated.PersonServiceCorba.Abm;
import ar.com.nextel.corba.generated.PersonServiceCorba.AbmHelper;
import ar.com.nextel.corba.generated.PersonServiceCorba.Person;

public class ClientCorba {


//	public static void main2(String args[]) {
//		try {
//			Abm abm;
//			  // Create and initialize the ORB 
//	    	Properties props = new Properties();
//	        props.put("org.omg.CORBA.ORBInitialPort", "1051");
//	        props.put("org.omg.CORBA.ORBInitialHost", "arpalHPd002");
//	        ORB orb = ORB.init(args, props);
//	        
//	        // Obtiene el contexto de nombrado raiz 
//	        org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 
//	        NamingContext ncRef = NamingContextHelper.narrow(objRef);
//
//	        // Resuelve la referencia al objeto en el nombrado 
//	        NameComponent nc = new NameComponent("myPersonService2", ""); 
//	        NameComponent path[] = {nc}; 
//	        abm = AbmHelper.unchecked_narrow(ncRef.resolve(path));
//
//	        // Llama al objeto servidor Hello e imprime el resultado 
//	        String hello = abm.saySomething();
//	        System.out.println(hello);
//
//
//		} catch (Exception e) {
//			System.out.println("ERROR : " + e);
//			e.printStackTrace(System.out);
//		}
//	}
	
	public static void main(String args[]) {
		
//		Connection conn = null;
//        String driverName = "oracle.jdbc.driver.OracleDriver";
//        String connectionUrl = "jdbc:oracle:thin:@bashpapm.nextel.com.ar:1697/";
//        String databaseName = "BPSD3";
//        String userName = "mnp";
//        String password = "mnp123";
//        try {
//                // Loading Driver
//                Class.forName(driverName);
//                // Creating Connection
//                conn = DriverManager.getConnection(connectionUrl + databaseName,
//                                userName, password);
//                // Setting auto commit false
//                conn.setAutoCommit(false);
//                System.out.println("Databese Connection Done........");
//        } catch (Exception e) {
//                System.out.println(e.toString());
//                System.out.println("Error In Connection");
//                System.exit(0);
//        }
        try {
        	
			Abm abm;
			  // Create and initialize the ORB 
	    	Properties props = new Properties();
	        props.put("org.omg.CORBA.ORBInitialPort", "1051");
	        props.put("org.omg.CORBA.ORBInitialHost", "arpalHPd002");
	        ORB orb = ORB.init(args, props);
	        
	        // Obtiene el contexto de nombrado raiz 
	        org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 
	        NamingContext ncRef = NamingContextHelper.narrow(objRef);

	        // Resuelve la referencia al objeto en el nombrado 
	        NameComponent nc = new NameComponent("myPersonService2", ""); 
	        NameComponent path[] = {nc}; 
	        abm = AbmHelper.unchecked_narrow(ncRef.resolve(path));

	        // Llama al objeto servidor Hello e imprime el resultado 
	        System.out.println(abm.saySomething());
        	
        		
        	
//            conn.commit();
                
        } catch (Exception e) {
                System.out.println(e.toString());
                System.exit(0);
        } 
//        finally {
//                try {
//					conn.close();
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//                System.out.println("Connection Closed..........");
//        }
		
	}
}
